# 构建阶段
FROM node:20-alpine as builder

# 作者信息
LABEL maintainer="Logan.Li"
LABEL description="News Platform Admin UI"

# 设置工作目录
WORKDIR /app

# 复制package.json和package-lock.json
COPY package*.json ./

# 复制源代码
COPY . .

# 使用缓存挂载安装依赖并构建
RUN --mount=type=cache,target=/app/node_modules,id=news-admin-ui-node-modules \
    npm ci --silent && npm run build

# 生产阶段
FROM nginx:alpine

# 复制构建产物到nginx目录
COPY --from=builder /app/dist /usr/share/nginx/html

# 复制nginx配置文件
COPY nginx.conf /etc/nginx/nginx.conf

# 暴露端口
EXPOSE 80

# 启动nginx
CMD ["nginx", "-g", "daemon off;"]
